package service.impl;

import common.AjaxResult;
import dao.FunctionDAO;
import entity.Function;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import service.FunctionService;

import java.util.List;

/**
 * Created by asus on 2017/6/17.
 */
@Service("functionService")
public class FunctionServiceImpl implements FunctionService {
    @Autowired
    private FunctionDAO functionDAO;

    /**
     * 增加功能
     *
     * @param function
     */
    @Override
    public void addFunction(Function function) {
        functionDAO.save(function);
    }

    /**
     * 根据功能id更新其url信息
     *
     * @param id
     * @param url
     */
    @Override
    public void updateUrl(Long id, String url) {
        functionDAO.updateUrl(id, url);
    }

    /**
     * 分页查询指定父节点的子节点
     *
     * @param page
     * @param size
     * @param parentId
     * @return 功能集合
     */
    @Override
    public List<Function> getFunction(int page, int size, Long parentId) {
        return functionDAO.findFunctions(page, size, parentId);
    }

    /**
     * 根据id删除功能
     *
     * @param id
     * @return
     */
    @Override
    public AjaxResult deleteFunctionById(Long id) {
        functionDAO.deleteById(id);
        return AjaxResult.success();
    }

    /**
     * 查询全部功能
     *
     * @return
     */
    @Override
    public List<Function> getAllFunctions() {
        return functionDAO.findAllFunction();
    }
}
